package com.newdjk.newdoctor.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.gson.Gson;
import com.newdjk.newdoctor.R;
import com.newdjk.newdoctor.dialog.ShareDialog;
import com.newdjk.newdoctor.entity.PatientListEntity;
import com.newdjk.newdoctor.ui.OrderListActivity;
import com.newdjk.newdoctor.ui.WebViewActivity;
import com.newdjk.newdoctor.utils.Contants;
import com.newdjk.newdoctor.utils.GlideUtils;
import com.newdjk.newdoctor.view.CircleImageView;
import com.newdjk.okhttp.entity.OrderListEntity;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.text.SimpleDateFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OrderListAdapter extends BaseQuickAdapter<OrderListEntity.ReturnDataBean, BaseViewHolder> {

    List<OrderListEntity.ReturnDataBean> mPaintList;

    public OrderListAdapter(@Nullable List<OrderListEntity.ReturnDataBean> data) {
        super(R.layout.order_item_list, data);
        mPaintList = data;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder helper, OrderListEntity.ReturnDataBean returnDataBean) {

        //501下单成功通知   502发货通知  503 取消通知  504订单退款通知   505订单退款失败通知   506订单完成
        //消息类型(1-下单成功通知，2-订单发货通知，3-订单取消通知，4-订单退款成功提醒，5-订单退款失败提醒，6-订单已完成通知)
        helper.setText(R.id.shop_name,TextUtils.isEmpty(returnDataBean.getSupplierName())?"":returnDataBean.getSupplierName());
        int type=returnDataBean.getMessageType();
        //消息类型(1-下单成功通知，2-订单发货通知，3-订单取消通知，4-订单退款成功提醒，5-订单退款失败提醒，6-订单已完成通知)
        TextView ordertext=helper.findView(R.id.order_type_desc);
        String medName=returnDataBean.getMedicationName();
        int count=returnDataBean.getMedicationNum();
        if (TextUtils.isEmpty(medName)){

        }else {
            if (medName.length()>10){
                medName=medName.substring(0,10)+"...";
            }
        }

        switch (type){
            case 1:
                ordertext.setText("您的订单已下单");
               // ordertext.setTextColor(getContext().getResources().getColor(R.color.ordernotfinish));
                helper.setText(R.id.medicine_name,"您的药品订单["+medName+"]已下单，等待商家发货");

                break;
            case 2:
                ordertext.setText("您的订单已发货");
               // ordertext.setTextColor(getContext().getResources().getColor(R.color.orderfinish));
                helper.setText(R.id.medicine_name,"您的药品订单["+medName+"]已经发出了，请及时关注订单状态");

                break;
            case 3:
                ordertext.setText("您的订单已退款");//订单取消通知
               // ordertext.setTextColor(getContext().getResources().getColor(R.color.ordernotfinish));
                helper.setText(R.id.medicine_name,"您的药品订单["+medName+"]已退款，退款金额["+returnDataBean.getAmount()+"元]");

                break;
            case 4:
                ordertext.setText("您的订单已退款");//您的药品订单[感冒灵胶囊、小柴胡…]退款失败，退款金额[66.23元]
               // ordertext.setTextColor(getContext().getResources().getColor(R.color.orderfinish));
//                helper.setVisible(R.id.tv_tuikuan_price,true);
//                helper.setVisible(R.id.tv_tuikuan_reason,true);
//                helper.setText(R.id.tv_tuikuan_price,"退款金额："+returnDataBean.getAmount()+"");
//                helper.setText(R.id.tv_tuikuan_reason,"退款原因："+(TextUtils.isEmpty(returnDataBean.getReason())?"":returnDataBean.getReason())+"");
                helper.setText(R.id.medicine_name,"您的药品订单["+medName+"]已退款，退款金额["+returnDataBean.getAmount()+"元]");

                break;
            case 5:
                ordertext.setText("您的订单退款失败");
                //ordertext.setTextColor(getContext().getResources().getColor(R.color.ordernotfinish));
//                helper.setVisible(R.id.tv_tuikuan_price,true);
//                helper.setVisible(R.id.tv_tuikuan_reason,true);
//                helper.setText(R.id.tv_tuikuan_price,"退款金额："+returnDataBean.getAmount()+"");
//                helper.setText(R.id.tv_tuikuan_reason,"驳回原因："+(TextUtils.isEmpty(returnDataBean.getReason())?"":returnDataBean.getReason())+"");
                helper.setText(R.id.medicine_name,"您的药品订单["+medName+"]退款失败，退款金额["+returnDataBean.getAmount()+"元]");

                break;
            case 6:
                ordertext.setText("您的订单已完成");
               // ordertext.setTextColor(getContext().getResources().getColor(R.color.orderfinish));
                helper.setText(R.id.medicine_name,"您的药品订单["+medName+"]已完成，期待您的下次光临");

                break;

        }
        ImageView avatar = helper.getView(R.id.avatar);
      //  ImageView imofforimg = helper.getView(R.id.im_offor_img);
        GlideUtils.loadMedicaineCommonmage(returnDataBean.getMedicationPicture(), avatar);
       // GlideUtils.loadCommonmage(returnDataBean.getSupplierPicture(), imofforimg);
        String time=returnDataBean.getMessageTime();
        if (TextUtils.isEmpty(time)){
            helper.setText(R.id.time,"");
        }else {
            helper.setText(R.id.time,""+returnDataBean.getMessageTime().substring(0,11));
        }

        int isread=returnDataBean.getIsRead();
        if (isread==0){
            helper.setVisible(R.id.order_unread_num,true);
        }else {
            helper.setVisible(R.id.order_unread_num,false);

        }

//        LinearLayout toshopIndex=helper.findView(R.id.to_shop_index);
//        toshopIndex.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//
//                Intent caijiintent = new Intent(getContext(), WebViewActivity.class);
//                caijiintent.putExtra(Contants.TYPE, 33);
//                caijiintent.putExtra("MedicationId", returnDataBean.getMedicationId()+ "");
//                caijiintent.putExtra("SupplierId", returnDataBean.getSupplierId()+ "");
//                getContext().startActivity(caijiintent);
//
//            }
//        });

    }



}